#cmake file for project myrpc
#author:unknow_author
#created:2022/04/13
##! 用于velrelcm.sh 的 变量搜索正则表达式, 不要轻易修改
##! @PRJNAME_REG@          (project\s*\(\s*)([[:alnum:]]+)(\s+.*\))
##! @VERSION_REG@          (project\s*\(\s*[[:alnum:]]+\s+VERSION\s+)(\S*)(.*\))
##! @DESC_REG@             (set\s*\(\s*VRTEST_VER_DESC\s+)(\S*)?(\s*\))
##! @SNAPSHOT_REG@         (project\s*\(\s*[[:alnum:]]+\s+VERSION\s+[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)(\.1)?(.*\))
##! @BEANCH_REG@           (set\s*\(\s*VRTEST_SCM_BRANCH\s+)(\S*)?(\s*\))
##! @COMMIT_REG@           (set\s*\(\s*VRTEST_SCM_COMMIT\s+)(\S*)?(\s*\))
##! 用于头文件(header)中搜索版本定义的正则表达
##! @H_VERSION_MAJOR_REG@  (#define\s+VRTEST_VERSION_MAJOR\s+)(\S+)(\s*)
##! @H_VERSION_MINOR_REG@  (#define\s+VRTEST_VERSION_MINOR\s+)(\S+)(\s*)
##! @H_VERSION_PATCH_REG@  (#define\s+VRTEST_VERSION_PATCH\s+)(\S+)(\s*)
##! @H_VERSION_SNAPSHOT_REG@  (#define\s+VRTEST_VERSION_SNAPSHOT)(\s+\S+)(\s*)
cmake_minimum_required( VERSION 3.0 )
if(POLICY CMP0048)
  cmake_policy(SET CMP0048 NEW)
endif()
# 3.0以上版本才允许使用VERSION option
project(myrpc_client VERSION 0.0.0.1 LANGUAGES C CXX)
#判断编译类型和版本是否满足编译要求
list(FIND CMAKE_CXX_COMPILE_FEATURES cxx_std_11 _cxx11_enable)
if(NOT _cxx11_enable)
	message(FATAL_ERROR "Compiler not supported C++ 11 standard")
endif()
unset(_cxx11_enable)

# 要求编译器支持C++11
set(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
# for generators = cmake_find_package
# generators 为 cmake_find_package 时会在 CMAKE_BINARY_DIR 下为所有依赖库生成对应FindXXXX.cmake脚本
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
if(MSVC)
	#关闭C4819警告
	add_definitions("/wd4819")		
	message(STATUS "optional:/wd4819")
	#关闭CRT_SECURE警告
	add_definitions(-D_CRT_SECURE_NO_WARNINGS)
	message(STATUS "optional:-D_CRT_SECURE_NO_WARNINGS")
endif(MSVC)
if(CMAKE_COMPILER_IS_GNUCXX)
	set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++" )
	set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++" )
	if(WIN32)
		set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc" )
		set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc" )
	endif()
endif()
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

##############设置目标文件生成位置#####################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
find_package(common_source_cpp REQUIRED)
# 查找 thrift库
find_package(Thrift REQUIRED)

# 获取common_source_cpp的文件夹
get_target_property(_common_source_includes common_source_cpp::common_source_cpp INTERFACE_INCLUDE_DIRECTORIES)
list(GET _common_source_includes 0 COMMON_SOURCE_LOCATION)
MESSAGE(STATUS COMMON_SOURCE_LOCATION=${COMMON_SOURCE_LOCATION})
unset(_common_source_includes)
set( SUBDIRECTORIES src)
foreach( subdir ${SUBDIRECTORIES} )
	if( IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/${subdir}" )
		MESSAGE( STATUS "Found sub project ${subdir}, adding it" )
		add_subdirectory( ${subdir} )
	endif()
endforeach()

